<template>
  <div class="myContainer">
    <el-row class="myTitleBorderBottom">
      <el-col :span="12" class="myLineHeight_40px">{{this.title}}</el-col>
      <el-col :span="12" class="myTextAlignRight">
        <!-- <a href="http://i.jimeicang.com:8080/appAdmin_order_detail/excel" class="myExBtn">导出统计报告</a> -->
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px" :gutter="10">
      <el-col :span="3">
        <template>
          <el-select 
            v-model="orderstatus"
            clearable
            placeholder="订单状态">
            <el-option
              v-for="item in orderstatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="3">
        <template>
          <el-select 
            v-model="userstatus"
            clearable
            placeholder="是否催单">
            <el-option
              v-for="item in userstatusList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="3">
        <template>
          <el-select 
            v-model="type"
            clearable
            placeholder="日期">
            <el-option
              v-for="item in typeList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="6">
        <el-date-picker
          v-model="time"
          type="daterange"
          format="yyyy-MM-dd"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-col>
      <el-col :span="3">
        <el-input placeholder="请输入关键词" v-model="kw"></el-input>
      </el-col>
      <el-col :span="2">
        <el-button type="primary" class="myBgGreen" @click="onSearch">查 询</el-button>
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="24">
        <el-table
          v-loading="loading"
          :data="tableData"
          :border = true
          :row-class-name="tableRowClassName"
          style="width: 100%">
          <!-- <el-table-column label="收货人信息"> -->
          <el-table-column
            width="100"
            prop="CONSIGNEE"
            label="收货人">
          </el-table-column>
          <el-table-column
            prop="CONSIGNEETEL"
            width="120"
            label="收货电话">
          </el-table-column>
          <!-- </el-table-column> -->
          <!-- <el-table-column label="订单信息">             -->
          <!-- <el-table-column
            width="80"
            label="订单类型">
            <template scope="scope">
              {{scope.row.ORDERTYPE | onOrderType}}
            </template>
          </el-table-column> -->
          <el-table-column
            width="100"
            label="订单总金额">
            <template scope="scope">
              <el-button type="text" title="点击查看" @click="onGetMoneyDetail(scope.row.ORDER_ID)" class="myColorRed" size="big">{{scope.row.TOTALFEE}}元</el-button>
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            label="配送状态">
            <template scope="scope">
              {{scope.row.SHIPPINGSTATUS | onShippingStatus}}
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            label="支付状态">
            <template scope="scope">
              {{scope.row.PAYSTATUS | onPaystatus}}
            </template>
          </el-table-column>
          <el-table-column
            prop="ADDTIME"
            width="160"
            label="创建时间">
          </el-table-column>
          <el-table-column
            prop="PAYTIME"
            width="160"
            label="支付时间">
          </el-table-column>
          <el-table-column
            prop="ORDERPAYNO"
            width="140"
            label="支付号">
          </el-table-column>
          <el-table-column
            prop="ORDERNO"
            width="140"
            label="订单号">
          </el-table-column>
          <!-- </el-table-column> -->
          <el-table-column
            width="120"
            fixed="right"
            label="订单状态">
            <template scope="scope">
              <span v-if="scope.row.ORDERSTATUS==0 && scope.row.PAYSTATUS==0">
                未付款
              </span>
              <span v-else>
                {{scope.row.ORDERSTATUS | onOrderStatus}}
              </span>
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            fixed="right"
            label="催单状态">
            <template scope="scope">
             <!--  {{scope.row.URGESTATUS | onUserstatus}} -->
              <span v-if="scope.row.URGESTATUS==0">未催单</span>
              <span v-if="scope.row.URGESTATUS==1" style="color: #f00">已催单</span>
            </template>
          </el-table-column>
          <el-table-column
            width="150"
            fixed="right"
            label="订单备注">
            <template scope="scope">
              <span v-if="scope.row.ORDERTIPS==''">暂无备注</span>
              <span v-else>{{scope.row.ORDERTIPS}}</span>
              <!-- <el-tooltip class="item" effect="dark" :content='"用户备注："+scope.row.ORDERTIPS' placement="bottom">
                <el-button type="text" class="look" size="small">订单备注</el-button>
              </el-tooltip> -->
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            fixed="right"
            label="商品信息">
            <template scope="scope">
              <el-button type="text" title="点击查看" @click="onCommodityDetail(scope.row.ORDER_ID)" class="look" size="small">商品信息</el-button>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            fixed="right"
            width="100">
            <template scope="scope">
              <span v-if="scope.row.ORDERSTATUS==0 && scope.row.PAYSTATUS==2">
                <el-button type="text" @click="onConfirm(scope.row.ORDER_ID,scope.$index,scope.row.ORDERPAYNO,scope.row.PAYSTATUS)" class="look" size="small">确认</el-button>
              </span>
              <span v-if="(scope.row.ORDERSTATUS==1 && scope.row.PAYSTATUS==2) || (scope.row.ORDERSTATUS==3 && scope.row.PAYSTATUS==2 && scope.row.SHIPPINGSTATUS==0)">
                <el-button type="text" @click="onDistribution(scope.row.ORDER_ID)" class="look" size="small">已配货</el-button>
              </span>
              <span v-if="scope.row.ORDERTYPE==3">
                <el-button type="text" @click="onSee(scope.row.ORDER_ID)" class="look" size="small">查看</el-button>
              </span>
              <span v-if="scope.row.PAYSTATUS>=2 && scope.row.SHIPPINGSTATUS>=1">
                <span v-if="scope.row.SHINPTYPE==0">
                  <span v-if="scope.row.ORDERSTATUS==3 && scope.row.PAYSTATUS==2 && scope.row.SHIPPINGSTATUS==1">
                    <el-button type="text" @click="onOKbution(scope.row.ORDER_ID)" class="look" size="small">确认收货</el-button>
                  </span>
                  <div v-else>门店自取</div>
                </span>
                <span v-if="scope.row.SHINPTYPE==1">
                  <el-button type="text" @click="onSeeInfo(scope.row.ORDER_ID)" class="look" size="small">配送信息</el-button>
                </span>
              </span>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">                    
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="page_num"
            :page-sizes="[10, 15]"
            :page-size="page_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
          </el-pagination>
        </div>
      </el-col>
    </el-row>
    
    <!-- 点击金额出现的弹出框 start -->
    <el-dialog title="信息" class="myRoleDialog" :visible.sync="msgDialogVisible">
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          商品总价:
        </el-col>
        <el-col :span="18">
          <el-input placeholder="商品总价" v-model="GOODSMONEY" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          抵扣金额:
        </el-col>
        <el-col :span="18">
          <el-input placeholder="抵扣金额" v-model="COUPONPAY" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          支付金额:
        </el-col>
        <el-col :span="18">
          <el-input placeholder="支付金额"  v-model="ONLINEPAY" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          退款金额:
        </el-col>
        <el-col :span="18">
          <el-input placeholder="退款金额"  v-model="REFUNDFEE" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          打包费:
        </el-col>
        <el-col :span="18">
          <el-input placeholder="退款金额"  v-model="PACKFEE" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          配送费:
        </el-col>
        <el-col :span="18">   
          <el-input placeholder="退款金额"  v-model="SHIPPINGFEE" :readonly="true"></el-input>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer"></div>
    </el-dialog>   
    <!-- 点击金额出现的弹出框 end -->
    <!-- 商品详细 start -->
    <el-dialog title="信息" :visible.sync="onCommodityDialogVisible">
      <el-row class="myPaddingBottom_10px">
        <el-table
          ref="multipleTable"
          :data="tableDataCommodity"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            label="商品类型">
            <template scope="scope">
              {{scope.row.GOODSTYPE | onGoodstype}}
            </template>
          </el-table-column>
          <el-table-column
            prop="GOODSNAME"
            label="商品名称">
          </el-table-column>
          <el-table-column
            label="logo图片">
            <template scope="scope">
              <a :href='EBIZ_SHOW_PIC_API+scope.row.LOGOIMG' target="_blank">
                <img :src='EBIZ_SHOW_PIC_API+scope.row.LOGOIMG' width="50" height="50"/>
              </a>
            </template>
          </el-table-column>
          <el-table-column
            prop="SPECIFICATIONS"
            label="商品规格">
          </el-table-column>
          <el-table-column
            label="是否促销">
            <template scope="scope">
              {{scope.row.ISPROMOTION==0?"否":"是"}}
            </template>
          </el-table-column>
          <el-table-column
            label="销售价格">
            <template scope="scope">
              {{scope.row.PRICE}}元
            </template>
          </el-table-column>
          <el-table-column
            prop="AMOUNT"
            label="购买数量">
          </el-table-column>
        </el-table>
      </el-row>
      <div slot="footer" class="dialog-footer"></div>
    </el-dialog>
    <!-- 商品详细 end -->
    <!-- 确认信息 start -->
    <el-dialog title="信息" :visible.sync="onConfirmDialogVisible">
      <el-row class="myPaddingBottom_10px">
        <el-table
          ref="multipleTable"
          :data="tableDataCommodity"
          :border = true
          :stripe = true
          style="width: 100%"
          @selection-change="handleSelectionChange">
          <el-table-column
            label="商品类型">
            <template scope="scope">
              {{scope.row.GOODSTYPE | onGoodstype}}
            </template>
          </el-table-column>
          <el-table-column
            prop="GOODSNAME"
            label="商品名称">
          </el-table-column>
          <el-table-column
            label="logo图片">
            <template scope="scope">
              <a :href='EBIZ_SHOW_PIC_API+scope.row.LOGOIMG' target="_blank">
                <img :src='EBIZ_SHOW_PIC_API+scope.row.LOGOIMG' width="50" height="50"/>
              </a>
            </template>
          </el-table-column>
          <el-table-column
            prop="SPECIFICATIONS"
            label="商品规格">
          </el-table-column>
          <el-table-column
            label="是否促销">
            <template scope="scope">
              {{scope.row.ISPROMOTION==0?"否":"是"}}
            </template>
          </el-table-column>
          <el-table-column
            label="销售价格">
            <template scope="scope">
              {{scope.row.PRICE}}元
            </template>
          </el-table-column>
          <el-table-column
            prop="AMOUNT"
            label="购买数量">
          </el-table-column>
        </el-table>
      </el-row>
      <hr/>
      <el-row>
        <el-col :span="5" class="myLeftMsg">
           收货人:
        </el-col>
        <el-col :span="18" class="myLineHeight_40px">
          {{CONSIGNEE}}
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5" class="myLeftMsg">
           收货电话:
        </el-col>
        <el-col :span="18" class="myLineHeight_40px">
          {{CONSIGNEETEL}}
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5" class="myLeftMsg">
           收货地址:
        </el-col>
        <el-col :span="18" class="myLineHeight_40px">
          {{CONSIGNEEPROVINCE}} {{CONSIGNEECITY}} {{CONSIGNEEDISTRICT}} {{ADDRESS}}
        </el-col>
      </el-row>
      <el-row class="myPaddingBottom_10px">
        <el-col :span="5" class="myLeftMsg">
          配送方式:
        </el-col>
        <el-col :span="18" class="myLineHeight_40px">
          <span v-if="SHINPTYPE==0">门店自取</span>
          <span v-if="SHINPTYPE==1">送货上门</span>
        </el-col>
      </el-row>
      <hr/>
      <el-row>
        <el-col :span="5" class="myLeftMsg">
           接受或拒绝该订单:
        </el-col>
        <el-col :span="18" class="myLineHeight_40px">
          <template>
            <el-radio-group v-model="subOrderstatus">
              <el-radio :label="1">接受</el-radio>
              <el-radio :label="5">拒绝</el-radio>
            </el-radio-group>
          </template>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5" class="myLeftMsg">
           理由:
        </el-col>
        <el-col :span="19" class="myLineHeight_40px">
          <el-input type="textarea" placeholder="请输入理由" v-model="CONFIRMCONENT"></el-input>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" class="myBgGreen" @click="onConfirmDialogVisible = false">取 消</el-button>
        <el-button type="primary" class="myBgGreen" @click="onEditConfirm">保 存</el-button>
      </div>
    </el-dialog>
    <!-- 确认信息 end -->
    <!-- 配货员 start -->
    <el-dialog title="指派配货员" class="myRoleDialog" :visible.sync="distributionDialog" >
      <el-row :gutter="10">
        <el-col :span="20">
          <el-input placeholder="输入关键词" v-model="r_kw"></el-input>
        </el-col>
        <el-col :span="4" class="myTextAlignRight">
          <el-button type="primary" class="myBgGreen" @click="onSearchExaminer">查询</el-button>
        </el-col>
      </el-row>
      <div class="myPaddingTop_10px">
        <el-tree
          class="myOV_y_400px" 
          ref="dutyDlg"
          v-loading="dutyDlgListLoading"
          :data="distributionList"
          :props="dutyDlgProps"
          node-key="staff_id"
          @check-change="onChange"
          :render-content="renderContent"
          :filter-node-method="filterNode"
          show-checkbox>
        </el-tree>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" class="myBgGreen" @click="distributionDialog = false">取 消</el-button>
        <el-button type="primary" class="myBgGreen" @click="onDistributionOK">提 交</el-button>
      </div>
    </el-dialog>
    <!-- 配货员 end -->
    
    <!-- 确认收货 start -->
    <el-dialog title="确认收货" class="myRoleDialog" :visible.sync="okbutionDialog" >
      <el-row :gutter="10">
        <el-col :span="24">
          <el-input placeholder="请输入收货码" v-model="ok_kw"></el-input>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" class="myBgGreen" @click="okbutionDialog = false">取 消</el-button>
        <el-button type="primary" class="myBgGreen" @click="onOkbutionOK">提 交</el-button>
      </div>
    </el-dialog>
    <!-- 确认收货 end -->

    <!-- 查看团购信息 start -->
    <el-dialog 
      title="信息"
      :visible.sync="grouPurchaseDialog">
        <el-row :gutter="10">
          <el-col :span="7">
            <el-date-picker
              v-model="start"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="开始时间">
            </el-date-picker>
          </el-col>
          <el-col :span="7">
            <el-date-picker
              v-model="end"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              placeholder="结束时间">
            </el-date-picker>
          </el-col>
          <el-col :span="7">
            <el-input placeholder="请输入关键词" v-model="kw_p"></el-input>
          </el-col>
          <el-col :span="3">
            <el-button type="primary" class="myBgGreen" @click="onSearchP">查 询</el-button>
          </el-col>
        </el-row>
        <el-row class="myMarginTop_10px">
          <el-table
            ref="multipleTable"
            :data="tableDataP"
            :border = true
            :stripe = true
            style="width: 100%">
            <el-table-column
              prop="USER_ID"
              label="用户Id">
            </el-table-column>
            <el-table-column
              prop="ORDERNO"
              label="订单号">
            </el-table-column>
            <el-table-column
              prop="ADDTIME"
              label="参团时间">
            </el-table-column>
          </el-table>
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" class="myBgGreen" @click="grouPurchaseDialog = false">关 闭</el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 查看团购信息 end -->

    <!-- 查看配送信息 start -->
    <el-dialog 
      title="信息"
      :visible.sync="distributionInfoDialog">
        <el-row>
          <el-table
            ref="multipleTable"
            :data="tableDataDinfo"
            :border = true
            :stripe = true
            style="width: 100%">
            <el-table-column
              prop="DELIVERYMANNAME"
              label="配送员姓名">
            </el-table-column>
            <el-table-column
              prop="DELIVERYMANPHONE"
              label="配送员电话">
            </el-table-column>
            <el-table-column
              label="配送状态">
              <template scope="scope">
                {{scope.row.SHIPPINGSTATUS | onSHIPPINGSTATUS}}
              </template>
            </el-table-column>
            <el-table-column
              prop="SETTLEMENTSTATUS"
              label="结算状态">
              <template scope="scope">
                {{scope.row.SETTLEMENTSTATUS | onSETTLEMENTSTATUS}}
              </template>
            </el-table-column>
            <el-table-column
              prop="PAYTIME"
              label="支付时间">
            </el-table-column>
            <el-table-column
              prop="CONFIRMTIME"
              label="确认时间">
            </el-table-column>
            <el-table-column
              prop="DISTRIBUTETIME"
              label="派单时间">
            </el-table-column>
            <el-table-column
              prop="PICKUPTIME"
              label="取货时间">
            </el-table-column>
            <el-table-column
              prop="RECEIVETIME"
              label="送达时间">
            </el-table-column>
          </el-table>
        </el-row>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" class="myBgGreen" @click="distributionInfoDialog = false">关 闭</el-button>
        </div>
      </el-form>
    </el-dialog>
    <!-- 查看配送信息 end -->
  </div>
</template>

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myColorRed,.myColorRed span{
    color: #f00;
  }
  .myPaddingBottom_10px{
    padding-bottom: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .myMarginBottom_10px{
    margin-bottom: 20px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
    padding-right: 10px;
  }
  hr{
    border:none;
    border-top:1px solid #e6ebf5;
  }
  .myExBtn{
    background: #409eff;
    padding:12px 20px;
    border-radius: 4px;
    display: inline-block;
    outline: 0;
    margin:0;
    color: #fff;
    text-align: center;
    font-size: 12px;
  }
  .myOV_y_400px{
    max-height: 400px;
    min-height: 200px;
    overflow-y:scroll;
    border:1px solid #f2f2f2; 
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }
</style>

<script>
  import { getOrderList , getPriceDetail , getCommentDetail , confirmOrder , getDistributionUser , getGroupPurchase , saveDistributionUser , getDistributionInfo , isokCode } from '@/api/online';
  import { getCityList , province } from '@/api/commerce';
  import { EBIZ_SHOW_PIC_API } from '@/config/baseUrl';
  import qs from "querystring";

  export default {
    data(){
      return{  
        title:"超市订单管理",   
        loading:false, 
        tableData:[],
        tableDataCommodity:[],
        msgDialogVisible:false, 
        onCommodityDialogVisible:false, 
        onConfirmDialogVisible:false,
        total:null, //总条数  
        page_num: 1, //当前页码
        page_size: 10, //每页显示多少条 
        kw:"",
        ordertype:"",
        orderList:[
          {label:"超市订单",value:1},
          {label:"餐饮订单",value:2},
          {label:"团购订单",value:3}
        ],
        orderstatus:"",
        orderstatusList:[
          {label:"未支付",value:"-1"},
          {label:"商家未确认",value:0},
          {label:"商家已接单",value:1},
          {label:"商家配货完成",value:3},
          {label:"已取消",value:2},
          {label:"待评价",value:4},
          {label:"已完成",value:5}
        ],
        userstatus:"",
        userstatusList:[
          {label:"未催单",value:0},
          {label:"已催单",value:1}
        ],
        type:1,
        typeList:[
          {label:"创建日期",value:1},
          {label:"支付日期",value:2}
        ],
        startTime:"",
        endTime:"",
        GOODSMONEY:"",
        COUPONPAY:"",
        ONLINEPAY:"",
        REFUNDFEE:"",
        CONSIGNEE:"",
        CONSIGNEETEL:"",
        CONSIGNEEPROVINCE:"",
        CONSIGNEECITY:"",
        CONSIGNEEDISTRICT:"",
        PACKFEE:"",
        SHIPPINGFEE:"",
        ADDRESS:"",
        subOrderstatus:1,
        subNo:"",
        subPayStatus:"",
        CONFIRMCONENT:"",
        subO_id:"",
        distribution:"",
        distributionList:[],
        distributionDialog:false,
        grouPurchaseDialog:false,
        kw_p:"",
        start:"",
        end:"",
        tableDataP:[],
        subO_id:"",
        g_id:"",
        distributionInfoDialog:false,
        tableDataDinfo:[],
        time:[],
        r_kw:"",
        dutyDlgListLoading:false,
        dutyDlgProps: {
          children: 'children',
          label: 'user_name'
        },
        timeout:null,
        ok_kw:'',
        okbutionDialog:false,
        SHINPTYPE:'',
        EBIZ_SHOW_PIC_API:EBIZ_SHOW_PIC_API
      }
    },
    watch: {
      r_kw(val) {
        try{
          this.$refs.dutyDlg.filter(val);
        }catch(error){
          return;
        }
      }
    },
    created() {
      let vm=this;
      document.title=this.title;
      this.onGetOrderList();

      vm.timeout=setInterval(function(){
        vm.onGetOrderList();
      },30*1000);
    },
    filters: {
      onOrderType(val){
        let type={
          1:"超市订单",
          2:"餐饮订单",
          3:"团购订单"
        }
        return type[val];
      },
      onOrderStatus(val){
        let status={
          "-1":"未付款",
          0:"商家未确认",
          1:"商家已接单",
          2:"已取消",
          3:"商家配货完成",
          4:"待评价",
          5:"已完成"
        }
        return status[val];
      },
      onPaystatus(val){
        let status={
          "-1":"已退款",
          0:"未付款",
          1:"付款中",
          2:"已付款"
        }
        return status[val];
      },
      onShippingStatus(val){
        let status={
          0:"未发货",
          1:"配送中",
          2:"已确认收货"
        }
        return status[val];
      },
      onUserstatus(val){
        let status={
          0:"未催单",
          1:"已催单"
        }
        return status[val];
      },
      onGoodstype(val){
        let type={
          1:"超市商品",
          2:"餐饮商品",
          3:"团购商品"
        }
        return type[val];
      },
      onSHIPPINGSTATUS(val){
        let type={
          0:"未取货",
          1:"已取货",
          2:"已取消"
        }
        return type[val];
      },
      onSETTLEMENTSTATUS(val){
        let type={
          0:"未完成",
          1:"已完成"
        }
        return type[val];
      }
    },
    methods:{
      filterNode(value, data) {
        if (!value) return true;
        return data.user_name.indexOf(value) !== -1;
      },
      renderContent:function(createElement, { node, data, store }) {
        var vm = this;
        return createElement(
          'div', 
          {
            attrs:{
              style:"width:100%",
              title:`联系方式：${node.data.phone}`
            }
          },
          [
            createElement('span', node.label),
            createElement('span', 
              {attrs:{
                style:"float: right; margin-right: 20px"
              }},
              `${node.data.phone}`
            )
          ]
        );
      },
      onGetOrderList() {//拉取列表
        let vm = this;
        if(vm.time){
          vm.startTime=this.time[0];
          vm.endTime=this.time[1];
        }else{
          vm.startTime="";
          vm.endTime="";
        }
        const params = {
          rows:vm.page_size,
          page:vm.page_num,
          ORDERNO:encodeURI(vm.kw),
          start:vm.startTime,
          end:vm.endTime,
          TYPE:vm.type,
          URGESTATUS:vm.userstatus,
          ORDERSTATUS:vm.orderstatus,
          ORDERTYPE:1
        }
        vm.loading=true;
        getOrderList(params)
        .then(response => {
          let res = response.data;
          vm.tableData = res.rows;
          vm.total = res.total;
          vm.loading=false;
        })
        .catch(error => {
          vm.loading=false;
          //console.log("拉取列表失败",error);
        });
      },
      handleSizeChange(val) {
        this.page_size = val;
        this.onGetOrderList();
      },
      handleCurrentChange(val) {
        this.page_num = val;
        this.onGetOrderList();
      },
      handleSelectionChange(val) {
      },
      onSearch(){//查询
        this.onGetOrderList();
      },
      onGetMoneyDetail(o_id){//拉取金额详细
        let vm=this;
        let params={
          ORDER_ID:o_id
        }
        getPriceDetail(params).then(response => {
          let res=response.data.OBJECT;
          vm.GOODSMONEY=res.GOODSMONEY;
          vm.COUPONPAY=res.COUPONPAY;
          vm.ONLINEPAY=res.ONLINEPAY;
          vm.REFUNDFEE=res.REFUNDFEE;
          vm.SHIPPINGFEE=res.SHIPPINGFEE;
          vm.PACKFEE=res.PACKFEE;
          vm.msgDialogVisible=true;
          console.log("拉取成功",res)
        }).catch(error => {
          console.log("拉取失败")
        })
      },
      onCommodityDetail(o_id){//拉取商品详细
        let vm=this;
        let params={
          ORDER_ID:o_id
        }
        getCommentDetail(params).then(response => {
          let res=response.data.OBJECT.varList;
          vm.tableDataCommodity=res;
          vm.onCommodityDialogVisible=true;
        }).catch(error => {

        })
      },
      onConfirm(o_id,index,o_no,p_status){//确认
        let vm=this;
        vm.subOrderstatus=1;
        vm.CONFIRMCONENT="";
        vm.subNo=o_no;
        vm.subPayStatus=p_status;
        vm.subO_id=o_id;
        let params={
          ORDER_ID:o_id
        }
        getCommentDetail(params).then(response => {
          let res=response.data.OBJECT.varList;
          vm.tableDataCommodity=res;
        }).catch(error => {

        })
        vm.onConfirmDialogVisible=true;
        vm.CONSIGNEE=vm.tableData[index].CONSIGNEE;
        vm.CONSIGNEETEL=vm.tableData[index].CONSIGNEETEL;
        vm.SHINPTYPE=vm.tableData[index].SHINPTYPE;
        //console.log(vm.tableData[index].CONSIGNEEPROVINCE,vm.tableData[index].CONSIGNEECITY,vm.tableData[index].CONSIGNEEDISTRICT)
        vm.onGetProvinceList(vm.tableData[index].CONSIGNEEPROVINCE);//省
        vm.onGetCityList(vm.tableData[index].CONSIGNEECITY);//市
        vm.onGetCountyList(vm.tableData[index].CONSIGNEEDISTRICT);//区

        vm.ADDRESS=vm.tableData[index].ADDRESS;
      },
      onGetProvinceList(val){//拉取省
        for(let i=0; i<province.length; i++){
          if(val==province[i].value){
            this.CONSIGNEEPROVINCE=province[i].label;
          }
        }
      },
      onGetCityList(val){//拉取市
       let vm=this;
       let params={
        AREA_ID:val
       }
       getCityList(qs.stringify(params)).then(response => {
          let res=response.data.OBJECT;
          vm.CONSIGNEECITY=res[0].AREANAME;
       }).catch(error => {
       })
     },
     onGetCountyList(val){//拉取区县
       let vm=this;
       let params={
        AREA_ID:val
       }
       getCityList(qs.stringify(params)).then(response => {
          let res=response.data.OBJECT;
          vm.CONSIGNEEDISTRICT=res[0].AREANAME;
       }).catch(error => {
       })
      },
      onEditConfirm(){//点击确认保存
        let vm=this;
        if(vm.subOrderstatus==1){
          let params={
            // ORDERPAYNO:vm.subNo,
            ORDER_ID:vm.subO_id,
            PAYSTATUS:vm.subPayStatus,
            ORDERSTATUS:vm.subOrderstatus,
            CONFIRMCONENT:vm.CONFIRMCONENT==''?"商家已成功接单":vm.CONFIRMCONENT
          }
          vm.onConfirmOrder(params);
        }else{
          if(vm.CONFIRMCONENT==""){
            vm.$message.error("请填写拒绝的理由！");
          }else{
            let params={
              // ORDERPAYNO:vm.subNo,
              ORDER_ID:vm.subO_id,
              PAYSTATUS:vm.subPayStatus,
              ORDERSTATUS:vm.subOrderstatus,
              CONFIRMCONENT:vm.CONFIRMCONENT
            }
            vm.onConfirmOrder(params);
          }
        }
      },
      onConfirmOrder(params){//保存接口
        let vm=this;
        confirmOrder(qs.stringify(params)).then(response => {
          let res=response.data;
          vm.$message.success("执行成功！");
          vm.onConfirmDialogVisible=false;
          vm.onGetOrderList();
        }).catch(error => {
          vm.$message.error("执行失败！");
        })
      },
      onSearchExaminer(){
        this.onDistribution(this.subO_id);
      },
      onChange(a,b,c){
        let vm=this;
        if(b){
          vm.$refs.dutyDlg.setCheckedKeys([]);
          vm.$refs.dutyDlg.setCheckedKeys([a.staff_id]);
        }else{
          vm.$refs.dutyDlg.setCheckedKeys([]);
        }
      },
      onDistribution(o_id){//拉取配货员
        let vm=this;
        vm.distributionDialog=true;
        vm.subO_id=o_id;
        let params={
          NAME:encodeURI(vm.r_kw),
          ORDER_ID:o_id
        }
        vm.dutyDlgListLoading = true;
        getDistributionUser(params).then(response => {
          let res=response.data;
          vm.distributionList=res.ygList;
          //vm.dutyDlgList = response.ygList;
          vm.dutyDlgListLoading = false;
          console.log(res)
        }).catch(error => {
          vm.dutyDlgListLoading = false;
        })
      },
      onDistributionOK(){//确认配货员
        let vm=this,name="",phone="",id="";
        var pl = vm.$refs.dutyDlg.getCheckedNodes();
        if (pl.length > 0) {
          name=pl[0].user_name;
          phone = pl[0].phone;
          id = pl[0].staff_id;
        }else{
          return;
        }
        let params={
          ORDER_ID:vm.subO_id,
          DELIVERYMANNAME:name,//员工名称
          DELIVERYMANPHONE:phone,//员工电话
          DELIVERYMAN:id//员工id
        }
        saveDistributionUser(qs.stringify(params)).then(response => {
          let res=response.data;
          vm.$message.success("执行成功！");
          vm.distributionDialog=false;
          vm.onGetOrderList();
        }).catch(error => {

        })
      },
      onSee(o_id){//查看参团信息
        let vm=this;
        vm.grouPurchaseDialog=true;
        let params={
          GOODS_ID:vm.g_id,
          start:vm.start,
          end:vm.end,
          ORDERNO:vm.kw_p,
          ORDER_ID:o_id
        }
        getGroupPurchase(params).then(response => {
          let res=response.data;
          vm.tableDataP=res.OBJECT.varList;
          vm.g_id=res.OBJECT.GOODS_ID;
        }).catch(error => {

        })
      },
      onSearchP(){//团购搜索
        this.onSee();
      },
      onSeeInfo(o_id){//查看配送信息
        let vm=this;
        let params={
          ORDER_ID:o_id
        }
        getDistributionInfo(params).then(response => {
          let res=response.data;
          vm.tableDataDinfo[0]=res.OBJECT;
          vm.distributionInfoDialog=true;
          // console.log(res)
        }).catch(error => {

        })
      },
      tableRowClassName({row, rowIndex}) {
        if (row.ORDERSTATUS==0&&row.PAYSTATUS==2) {
          return 'warning-row';
        } else {
          //return 'success-row';
        }
        return '';
      },
      onOKbution(o_id){
        this.subO_id=o_id;
        this.okbutionDialog=true;
      },
      onOkbutionOK(){
        let vm=this;
        let params={
          ORDER_ID:vm.subO_id,
          VERIFICATIONCODE:vm.ok_kw
        }
        isokCode(qs.stringify(params)).then(response => {
          let res=response.data;
          if(res.SUCCESS){
            vm.$message.success("验证成功！");
            vm.okbutionDialog=false;
            vm.onGetOrderList();
          }else{
            vm.$message.error("验证失败！");
          }
          vm.ok_kw='';
          // console.log(res)
        }).catch(error => {
          // console.log(error)
        })
      }

    },
    beforeDestroy:function(){
      //console.log("beforeDestory");
    },
    destroyed:function(){
      // console.log("destroyed..");
      clearInterval(this.timeout);
    }

  }


</script>



